package com.x.servlet;

import com.x.bean.Achievement;
import com.x.bean.User;
import com.x.service.student.StudentService;
import com.x.service.student.StudentServiceImpl;
import com.x.service.user.UserService;
import com.x.service.user.UserServiceImpl;
import com.x.util.Constants;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * @author 13925
 */
public class StudentGetByCodeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        User userSession = (User) req.getSession().getAttribute("userSession");
        String code = userSession.getCode();
        StudentService studentService = new StudentServiceImpl();
        List<Achievement> studentByCode = studentService.getStudentByCode(code);
        System.out.println(studentByCode);
        if (studentByCode != null) {
            req.setAttribute("Achievement", studentByCode);
            req.getRequestDispatcher("studentview.jsp").forward(req, resp);
        } else {
            req.setAttribute("error","查询失败");
            req.getRequestDispatcher("studentview.jsp").forward(req, resp);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
